<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use app\models\UploadForm;
use yii\web\UploadedFile;
use app\models\Goods;
class UpController extends Controller
{
    public function actionUpload()
    {
        $model = new UploadForm();

        if (Yii::$app->request->isPost)
        {
            $model->imageFile = UploadedFile::getInstance($model, 'imageFile');

            $data=Yii::$app->request->post();//接收数据
            $arr=$model->upload();
            if ($arr['code']==false)//验证数据是否上传成功
            {
                return "文件上传失败";
            }
            $data['img']=$arr['arr'];//赋值调用

            $tell=new Goods();//实劣化

            $photo=$tell->add($data);//添加

            if($photo)//验证添加是否正确
            {
                echo "添加成功";
                return $this->redirect(['up/show']);
            }
            else
            {
                echo "添加失败";
                return $this->redirect(['up/upload']);
            }


        }

        return $this->render('upload', ['model' => $model]);
    }
    public function actionShow()//展示页面
    {
        $arr=new Goods();
        $data=$arr->show();
        return $this->render("show",['arr'=>$data]);
    }
}


?>